#include "MyEvent.h"

CMyEvent::CMyEvent(void)
{
#ifdef WIN32
	m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
#endif
}

CMyEvent::~CMyEvent(void)
{
#ifdef _WIN32
	if (m_hEvent)
	{
		CloseHandle(m_hEvent);
		m_hEvent = NULL;
	}
#endif
}

void CMyEvent::Set()
{
#ifdef _WIN32
	SetEvent(m_hEvent);
#endif
}

void CMyEvent::ReSet()
{
#ifdef _WIN32
	ResetEvent(m_hEvent);
#endif
}

int CMyEvent::Wait(unsigned long  dwTimeOut /*= 3*/)
{
#ifdef _WIN32
	DWORD dwRet = WaitForSingleObject(m_hEvent, dwTimeOut * 1000);
	switch (dwRet)
	{
	case WAIT_TIMEOUT:
		return -1;
	case WAIT_OBJECT_0:
		return 0;
	default:
		return -2;
	}
#endif	
}
